<?php 
	require('funkcije.php');
	require('validacija.php');
?>
<?php
	/* ADMIN DEFINED SETTINGS END*/
	if($_POST['delete_item'] > 0)
	{
		$result = mysql_query('DELETE FROM '.DB_PERFIX.'hfb_sets WHERE id='.$_POST['delete_item'].' LIMIT 1;');
	}
	switch ($_POST['action'])
	{
		case 'new_item':
			if($_POST['name'] != '')
			{
				$result  = 'SELECT * FROM '.DB_PERFIX.'hfb_sets WHERE border='.$_POST['border'].' AND '; 
				$result .= 'border2='.$_POST['border2'].' AND header='.$_POST['header'].' AND ';
				$result .= 'footer='.$_POST['footer'].' AND button='.$_POST['button'].' AND ';
				$result .= 'footer='.$_POST['footer'].' AND button='.$_POST['button'].' AND ';
				$result .= 'content_style="'.$_POST['content_style'].'" AND h_button='.$_POST['hbutton'].' AND ';
				$result .= 'f_button='.$_POST['fbutton'].' AND wrap_style="'.$_POST['wrap_style'].'" ;';
				
				$result = mysql_query($result);
				if(mysql_num_rows($result) < 1)
				{
					$insert  = "INSERT INTO ".DB_PERFIX."hfb_sets (`id`, `name`, `header`, `footer`, `border`, `border2`, `button`, `h_button`, `f_button`)"; 
					$insert .= "VALUES (NULL, '".$_POST['name']."', '".$_POST['header']."', '".$_POST['footer']."', '".$_POST['border']."', '".$_POST['border2']."', '".$_POST['button']."', '".$_POST['hbutton']."', '".$_POST['fbutton']."');";
					$result = mysql_query($insert);
				}
				else
				{
					while($row = mysql_fetch_array($result))
					{ $item['name'] = $row['name']; }
					$error['name'] = "Composition Allready Exists AS<strong>:".$item['name']."</strong>";
				}
			}
			break;
		case 'update':
			if($_REQUEST['item'] > 0)
			{   
				$update  = 'UPDATE '.DB_PERFIX.'hfb_sets SET ';
				if($_POST['name'] != '')
				{ $update .= 'name="'.$_POST['name'].'", '; }
				$update .= 'header='.$_POST['header'].', ';
				$update .= 'footer='.$_POST['footer'].', ';
				$update .= 'border='.$_POST['border'].', ';
				$update .= 'border2='.$_POST['border2'].', ';
				$update .= 'button='.$_POST['button'].', ';
				$update .= 'h_button='.$_POST['h_button'].', ';
				$update .= 'f_button='.$_POST['f_button'].', ';
				$update .= 'wrap_style="'.$_POST['wrap_style'].'", ';
				$update .= 'content_style="'.$_POST['content_style'].'" ';
				$update .= 'WHERE id='.$_REQUEST['item'].' LIMIT 1;';
				//echo $update;
				$update = mysql_query($update);
			}
	}
	if($_REQUEST['item'] > 0)
	{ $item['id'] = $_REQUEST['item']; }
?>
<form id="edit_form" action="?con=<?php echo $_REQUEST['con']; ?>" method="post" name="edit_form">
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background: #FFFFFF; margin-bottom:16px;">
	<?php if($_REQUEST['item'] > 0): ?>
	<tr>
		<td class="admin_cell" valign="top"  width="250"></td>
		<td colspan="2">
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td height="20" >
						<input type="hidden" name="action" value="update">
						<input type="submit" value="Save" style="padding-left:20px; padding-right:10px;  background-image: url('../images/system/save.gif'); border:1px solid #DDDDDD; height:20px;" class="buttons">
						<button name="delete_item" value="<?php echo $item['id']; ?>" style="padding-left:20px; padding-right:10px;  background-image: url('../images/system/delete.gif'); border:1px solid #DDDDDD;" class="buttons">Delete Template</button>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<?php else:?>
	<tr>
		<td class="admin_cell" valign="top"  width="250"></td>
		<td colspan="2">
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td height="20" >
						<input type="hidden" name="action" value="new_item">
						<input type="submit" value="Add new" style="padding-left:20px; padding-right:10px;  background-image: url('../images/system/save.gif'); border:1px solid #DDDDDD; height:20px;" class="buttons">
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<?php endif;?>
	<tr>
		<td class="admin_cell" width="150">Selected Composition Set:</td>
		<td class="admin_cell">
			<select name="item" onChange="edit_form.action.value=''; edit_form.submit();" style="width:300px;">
				<option value="" selected>None (New)</option>
				<?php 
					$result = mysql_query("SELECT * FROM ".DB_PERFIX."hfb_sets;");
					while($row = mysql_fetch_array($result))
					{
						if ($row['id'] == $_REQUEST['item'])
						{
							echo '<option value="'.$row['id'].'" selected>'.$row['name'].' - ['.$row['id'].']</option>';
							$item['name'] = $row['name'];
							$item['header'] = $row['header'];
							$item['footer'] = $row['footer'];
							$item['border'] = $row['border'];
							$item['border2'] = $row['border2'];
							$item['button'] = $row['button'];
							$item['h_button'] = $row['h_button'];
							$item['f_button'] = $row['f_button'];
							$item['content_style'] = $row['content_style'];
							$item['wrap_style'] = $row['wrap_style'];
							
							$item = $row['id'];
						}
						else
						{
							if (($row['header'] == $item['header']) && 
								($row['footer'] == $item['footer']) && 
								($row['border'] == $item['border']) && 
								($row['border2'] == $item['border2']) && 
								($row['button'] == $item['button']) && 
								($row['content_style'] == $item['content_style']) &&
								($row['wrap_style'] == $item['wrap_style']) &&
								($row['h_button'] == $item['hbutton']) && 
								($row['f_button'] == $item['fbutton']))
							{
								$item = $row['id'];
								echo '<option value="'.$row['id'].'" selected>'.$row['name'].' - ['.$row['id'].']</option>';
							}
							else
							{
								echo '<option value="'.$row['id'].'">'.$row['name'].' - ['.$row['id'].']</option>';
							}
						}
					}
				?>
			</select>
		</td>
		<td class="admin_cell_stat" width="150"></td>
	</tr>
	<tr>
		<td class="admin_cell">Name:</td>
		<td class="admin_cell">
			<input name="name" maxlength="70" type="text" value="<?php echo $item['name']; ?>" style="width:300">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</td>
		<td class="admin_cell_stat"><?php echo $NameStatus; ?></td>
	</tr>
	<tr>
		<td class="admin_cell" width="150">Composition Outer Border:</td>
		<td class="admin_cell">
			<select name="border" <?php if($_REQUEST['item'] > 0) { echo 'onChange="document.composition_form.submit()"'; } ?> style="width:300px;">
				<option value="0" selected>None</option>
				<?php 
					$result = mysql_query("SELECT id, name FROM ".DB_PERFIX."com_borders;");
					while($row = mysql_fetch_array($result))
					{
						if ($row['id'] == $item['border'])
						{
							echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
						}
						else
						{
							echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
						}
					}
				?>
			</select>
		</td>
		<td class="admin_cell_stat" width="150">
		</td>
	</tr>
	<tr>
		<td class="admin_cell" width="150">Composition Inner Border:</td>
		<td class="admin_cell">
			<select name="border2" <?php if($_REQUEST['item'] > 0) { echo 'onChange="document.composition_form.submit()"'; } ?> style="width:300px;">
				<option value="0" selected>None</option>
				<?php 
					$result = mysql_query("SELECT id, name FROM ".DB_PERFIX."com_borders;");
					while($row = mysql_fetch_array($result))
					{
						if ($row['id'] == $item['border2'])
						{
							
							echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
						}
						else
						{
							echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
						}
					}
				?>
			</select>
		</td>
		<td class="admin_cell_stat" width="150">
		</td>
	</tr>
	<tr>
		<td class="admin_cell" width="150">Composition Header Type:</td>
		<td class="admin_cell">
			<select name="header" <?php if($_REQUEST['item'] > 0) { echo 'onChange="document.composition_form.submit()"'; } ?> style="width:300px;">
				<option value="0" selected>None</option>
				<?php 
					$result = mysql_query("SELECT * FROM ".DB_PERFIX."com_headers;");
					while($row = mysql_fetch_array($result))
					{
						if ($row['id'] == $item['header'])
						{
							echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
						}
						else
						{ echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'; }
					}
				?>
			</select>
		</td>
		<td></td>
	</tr>
	<tr>
		<td class="admin_cell" width="150">Composition Footer Type:</td>
		<td class="admin_cell">
			<select name="footer" <?php if($_REQUEST['item'] > 0) { echo 'onChange="document.composition_form.submit()"'; } ?> style="width:300px;">
				<option value="0" selected>None</option>
				<?php 
					$result = mysql_query("SELECT * FROM ".DB_PERFIX."com_footers;");
					while($row = mysql_fetch_array($result))
					{
						if ($row['id'] == $item['footer'])
						{
							echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
						}
						else
						{
							echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
						}
					}
				?>
			</select>
		</td>
		<td></td>
	</tr>
	<tr>
		<td class="admin_cell" width="150">Header Button Type:</td>
		<td class="admin_cell">
			<select name="h_button" <?php if($_REQUEST['item'] > 0) { echo 'onChange="document.composition_form.submit()"'; } ?> style="width:300px;">
				<option value="0" selected>None</option>
				<?php 
					$result = mysql_query("SELECT * FROM ".DB_PERFIX."buttons;");
					while($row = mysql_fetch_array($result))
					{
						if ($row['id'] == $item['h_button'])
						{
							echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
						}
						else
						{
							echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
						}
					}
				?>
			</select>
		</td>
		<td></td>
	</tr>
	<tr>
		<td class="admin_cell" width="150">Footer Button Type:</td>
		<td class="admin_cell">
			<select name="f_button" <?php if($_REQUEST['item'] > 0) { echo 'onChange="document.composition_form.submit()"'; } ?> style="width:300px;">
				<option value="0" selected>Default</option>
				<?php 
					$result = mysql_query("SELECT * FROM ".DB_PERFIX."buttons;");
					while($row = mysql_fetch_array($result))
					{
						if ($row['id'] == $item['f_button'])
						{
							echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
						}
						else
						{
							echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
						}
					}
				?>
			</select>
		</td>
		<td></td>
	</tr>
	<tr>
		<td class="admin_cell" width="150">Inner Content Button Type:</td>
		<td class="admin_cell">
			<select name="button" <?php if($_REQUEST['item'] > 0) { echo 'onChange="document.composition_form.submit()"'; } ?>  style="width:300px;">
				<option value="0" selected>Default</option>
				<?php 
					$result = mysql_query("SELECT * FROM ".DB_PERFIX."buttons;");
					while($row = mysql_fetch_array($result))
					{
						if ($row['id'] == $item['button'])
						{
							echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
						}
						else
						{
							echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
						}
					}
				?>
			</select>
		</td>
		<td></td>
	</tr>
	<tr>
		<td valign="top" class="admin_cell" width="150">Element Wrapper Style:</td>
		<td class="admin_cell">
			<textarea name="wrap_style" style="width:300px; height:100px;"><?php echo $item['wrap_style']; ?></textarea>
		</td>
		<td></td>
	</tr>
	<tr>
		<td valign="top" class="admin_cell" width="150">Inner Content Style:</td>
		<td class="admin_cell">
			<textarea name="content_style" style="width:300px; height:100px;"><?php echo $item['content_style']; ?></textarea>
		</td>
		<td></td>
	</tr>
	<tr>
		<td class="admin_cell" width="150"></td>
		<td colspan="2"><br>
			<?php 
			$header_buttons = array 
			(
				'0' => array 
				(	'type' => $item['h_button'],
					'text' => 'Home',
					'link' => 'index.php',
					'action' => '',
					'submit' => '',
					'other' => '',
					'id' => '',
				),
				'1' => array 
				(
					'type' => $item['h_button'],
					'text' => 'Clear',
					'link' => '',
					'action' => "document.getElementById('register_user').reset();",
					'submit' => '',
					'other' => '',
					'id' => '',
				),
			);
			$footer_buttons = array 
			(
				'0' => array 
				(	'type' => $item['f_button'],
					'text' => 'Home',
					'link' => 'index.php',
					'action' => '',
					'submit' => '',
					'other' => '',
					'id' => '',
				),
				'1' => array 
				(
					'type' => $item['f_button'],
					'text' => 'Clear',
					'link' => '',
					'action' => "document.getElementById('register_user').reset();",
					'submit' => '',
					'other' => '',
					'id' => '',
				),
			);
			if($item['wrap_style'] != '')
			{ echo getWrapStyleTop($item['wrap_style']); }
			if(($item['border'] != '') && ($item['border'] != '0'))
			{require('../templates/borders/type_'.$item['border'].'_top.php'); }
			if($item['header'] != '')
			{echo getHeader($item['header'], 'Module', 'Name', $header_buttons, 0);}
			echo getWrapMidTop($item['id']);
			if(($item['border2'] != '') && ($item['border2'] != '0'))
			{require('../templates/borders/type_'.$item['border2'].'_top.php'); }
			?>
			<table class="container_type_<?php echo $item['id']; ?>_table_inner" width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td class="container_type_<?php echo $item['id']; ?>_td_inner"  style="<?php echo $item['content_style']; ?>">
						<strong>
						<font color="#FF0000">Content</font><font color="#00FF00"> Sample </font>
						<font color="#000000">Content</font><font color="#333333"> Sample </font>
						<font color="#666666">Content</font><font color="#999999"> Sample </font>
						<font color="#CCCCCC">Content</font><font color="#FFFFFF"> Sample </font>
						<font color="#0000FF">Content</font><font color="#FF00FF"> Sample </font>
						</strong><br>
						<?php 
						if($item['button'] > 0)
						{ ?><br>
						<table cellpadding="0" cellspacing="0" border="0" style="inherit">
							<tr>
								<td style="padding:2px;">
									<?php echo addButton($item['button'], 'Link', 'com_settings.php' , '' , '', '', '');?>
									<?php echo addButton($item['button'], 'Action', '' , '' , '', '', '');?>
									<?php echo addButton($item['button'], 'Submit Button', '' , '' , 'submit', 'disabled="true"', 'regButton');?>
								</td>
							</tr>
						</table>
						<?php
						}
						?>
						Module Text Module Text Module Text Module Text Module Text Module Text 
						Module Text Module Text Module Text Module Text Module Text Module Text 
						Module Text Module Text Module Text Module Text Module Text Module Text 
						Module Text Module Text Module Text Module Text Module Text Module Text 
						Module Text Module Text Module Text Module Text Module Text Module Text 
					</td>
				</tr>
			</table>
			<?php 
			if($item['border2'] > 0)
			{ require('../templates/borders/type_'.$item['border2'].'_bot.php'); }
			echo getWrapBot($item['id']);
			if($item['footer'] != '')
			{ echo getFooter($item['footer'], 'Footer Text', $footer_buttons); }
			if($item['border'] > 0)
			{ require('../templates/borders/type_'.$item['border'].'_bot.php'); }
			if($item['wrap_style'] != '')
			{ echo getWrapBot($item['id']); }
			?> 
		</td>
	</tr>
</table>
</form>
